
from rest_framework.generics import ListAPIView, RetrieveAPIView
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.pagination import PageNumberPagination

from . import models, serializer


class CourseCategoryListAPIView(ListAPIView):
	queryset = models.CourseCategory.objects.filter(is_show=True, is_deleted=False).order_by('orders')
	serializer_class = serializer.CourseCategoryModelSerializers


# 课程数据分页
class CoursesPagination(PageNumberPagination):
	page_size = 5
	page_query_param = 'page'


class CourseListAPIView(ListAPIView):
	queryset = models.Course.objects.filter(is_show=True, is_deleted=False).order_by('orders')
	serializer_class = serializer.CourseModelSerializers
	pagination_class = CoursesPagination
	filter_backends = [DjangoFilterBackend, ]
	filter_fields = ('course_category', )


class CourseDetailListView(RetrieveAPIView):
	queryset = models.Course.objects.filter(is_show=True, is_deleted=False)
	serializer_class = serializer.CourseDetailModelSerializer


class ChapterListView(ListAPIView):
	queryset = models.CourseChapter.objects.filter(is_show=True, is_deleted=False)
	serializer_class = serializer.ChapterModelSerializer
	filter_backends = [DjangoFilterBackend, ]
	filter_fields = ('course',)
